use IO::Socket;
use IO::Select;

$args = join(" ",@ARGV);
$armtcc = "armtcc.exe";
$remotecmd = "$armtcc $args";

sub mylog
{
	my($txt) = @_;
	open LOG,">>tcc.pl.txt";
	print LOG "$txt\n";
	close LOG;
}

if($args =~ /-E/)
{
	mylog("tcc.pl enter local");
	mylog("$armtcc $args");

	system("$armtcc $args");

	mylog("tcc.pl exit local");
} else {
	mylog("tcc.pl enter remote\n");

	$sock = IO::Socket::INET->new('127.0.0.1:8008') or die "$!";
	print $sock "$remotecmd\n";

	mylog("$remotecmd\n");

	while(<$sock>)
	{
		if(/^svr:end/)
		{
			0;
			last;
		}
		else
		{
			print "$_";
		}
	}

	mylog("/*tcc.pl exit remote*/\n");
}